package scauCmiScaffolding.compiled;

import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.taglib.RuntimeTagElement;
import org.eclipse.jet.taglib.TagInfo;

public class _jet_cmiHibernateProxyUtil_0 implements JET2Template {
    private static final String _jetns_c = "org.eclipse.jet.controlTags"; //$NON-NLS-1$

    public _jet_cmiHibernateProxyUtil_0() {
        super();
    }

    private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
    
    private static final TagInfo _td_c_get_1_9 = new TagInfo("c:get", //$NON-NLS-1$
            1, 9,
            new String[] {
                "select", //$NON-NLS-1$
            },
            new String[] {
                "$packageName", //$NON-NLS-1$
            } );

    public void generate(final JET2Context context, final JET2Writer __out) {
        JET2Writer out = __out;
        out.write("package ");  //$NON-NLS-1$        
        RuntimeTagElement _jettag_c_get_1_9 = context.getTagFactory().createRuntimeTag(_jetns_c, "get", "c:get", _td_c_get_1_9); //$NON-NLS-1$ //$NON-NLS-2$
        _jettag_c_get_1_9.setRuntimeParent(null);
        _jettag_c_get_1_9.setTagInfo(_td_c_get_1_9);
        _jettag_c_get_1_9.doStart(context, out);
        _jettag_c_get_1_9.doEnd();
        out.write(".util;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("import org.hibernate.proxy.HibernateProxy;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("import org.hibernate.proxy.LazyInitializer;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("//Hibernate 动态代理，获取懒加载的实例？？？？");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("public class CmiHibernateProxyUtil {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("\tpublic static <T> T deproxy(T obj) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tif (obj == null)");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\treturn obj;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tif (obj instanceof HibernateProxy) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t// Unwrap Proxy;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t// -- loading, if necessary.");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\tHibernateProxy proxy = (HibernateProxy) obj;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\tLazyInitializer li = proxy.getHibernateLazyInitializer();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\treturn (T) li.getImplementation();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\treturn obj;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("\tpublic static boolean isProxy(Object obj) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tif (obj instanceof HibernateProxy)");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\treturn true;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\treturn false;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("\tpublic static boolean isEqual(Object o1, Object o2) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tif (o1 == o2)");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\treturn true;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tif (o1 == null || o2 == null)");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\treturn false;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tObject d1 = deproxy(o1);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tObject d2 = deproxy(o2);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tif (d1 == d2 || d1.equals(d2))");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\treturn true;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\treturn false;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("\tpublic static boolean notEqual(Object o1, Object o2) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\treturn !isEqual(o1, o2);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("\tpublic static boolean isSame(Object o1, Object o2) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tif (o1 == o2)");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\treturn true;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tif (o1 == null || o2 == null)");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\treturn false;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tObject d1 = deproxy(o1);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tObject d2 = deproxy(o2);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tif (d1 == d2)");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\treturn true;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\treturn false;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("\tpublic static boolean notSame(Object o1, Object o2) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\treturn !isSame(o1, o2);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("\tpublic static Class getClassWithoutInitializingProxy(Object obj) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tif (obj instanceof HibernateProxy) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\tHibernateProxy proxy = (HibernateProxy) obj;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\tLazyInitializer li = proxy.getHibernateLazyInitializer();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\treturn li.getPersistentClass();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t// Not a Proxy.");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\treturn obj.getClass();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("}");  //$NON-NLS-1$        
        out.write(NL);         
    }
}
